﻿function initChart(server,cpuPoint,memPoint){
                Highcharts.chart('cpuMemInfo', {
                    chart: {
                        type: 'spline',
                        marginRight: 10,
                        events: {
                            load: function () {
                                var series0 = this.series[0],
                                    series1 = this.series[1],
                                    chart = this;
				function task(){
                                //timer = setTimeout(()=>{
                                    series0.addPoint(cpuPoint, false, true);
                                    series1.addPoint(memPoint, true, true);
				    var url = 'sysInfo/getCpuMemInfoActualTimeByServer';
				    jQuery.ajax({
					url:domain + url,
					type:"get",
					data:{"server":server},
					crossDomain:true,
					xhrFields:{
						withCredentials:true
					},
					success:function (data) {
						if(data.status == 200){
                            let serverData = data.data;
                            cpuPoint = [];
                            memPoint = [];
                            if (serverData != ''){
                                cpuPoint.push(serverData['t']);
                                cpuPoint.push(serverData['c']);
                                memPoint.push(serverData['t']);
                                memPoint.push(serverData['m']);
                            }

						}
						setTimeout(()=>{
						    task();
						},timeout)
					},
					error:function(data) {
						top.toastr.error("查询列表失败，请检查网络");
					}
				    })
				}
				task();
                            }
                        }
                    },
                    credits:{
                        enabled:false
                    },
                    title: {
                        text: 'Cpu内存使用率'
                    },
                    xAxis: {
                        type: 'datetime',
                        tickPixelInterval: 150
                    },
                    yAxis: {
                        title: {
                            text: '百分比'
                        }
                    },
                    legend: {
                        enabled: true
                    },
                    tooltip: {
                        formatter: function () {
                            return '<b>' + this.series.name + '</b><br/>' +
                                Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                                Highcharts.numberFormat(this.y, 2);
                        }
                    },
                    legend: {
                        enabled: true
                    },
                    series: [{
                        name: 'Cpu使用率',
                        data: (function () {
                            // 生成随机值
                            var data = [],
                                time = (new Date()).getTime(),
                                i;
                            for (i = -19; i <= 0; i += 1) {
                                data.push({
                                    x: time + i * 1000,
                                    y: 0
                                });
                            }
                            return data;
                        }())
                    },{
                        name: '内存使用率',
                        data: (function () {
                            // 生成随机值
                            var data = [],
                                time = (new Date()).getTime(),
                                i;
                            for (i = -19; i <= 0; i += 1) {
                                data.push({
                                    x: time + i * 1000,
                                    y: 0
                                });
                            }
                            return data;
                        }())
                    }]
                });
            }
